﻿using System;
using System.Linq;
using GdHotel.Data.Interfaces;

namespace GdHotel.Data.Repositories
{
    public class RoomTypesRepository : IRoomTypesRepository
    {
        private GdHotelEntities entities = new GdHotelEntities();

        public IQueryable<RoomType> FindAll()
        {
            return entities.RoomTypes.AsQueryable();
        }

        public IQueryable<RoomType> FindAllByLang(Language lang)
        {
            return entities.RoomTypes.Where(roomType => roomType.LanguageId == lang.Id).AsQueryable();
        }

        public RoomType GetById(Int32 id)
        {
            return entities.RoomTypes.SingleOrDefault(roomType => roomType.Id == id);
        }

        public void Insert(RoomType roomType)
        {
            entities.AddToRoomTypes(roomType);
        }

        public void Delete(RoomType roomType)
        {
            entities.RoomTypes.DeleteObject(roomType);
        }

        public void Save()
        {
            entities.SaveChanges();
        }

        public void Dispose()
        {
            entities.Dispose();
        }
    }
}
